<template>
    <section style="background: #fff;">
      <yd-infinitescroll :callback="loadList" ref="infinitescrollDemo" style="background: #fff;">

        <div class="list_item" slot="list" v-for="item,key in list" @click="detailInfo(item)">
          <ul>
            <li class="list_info" style="margin-top: 0">
              <span style="font-size: .30rem;font-weight: bold;text-align: left;">{{item.name}}</span>
              <div v-if="item.regStatus != undefined && item.regStatus != ''">
              <span style="width: .80rem;height: .50rem;border: 1px solid #6BBE52;line-height: .50rem;color: #6BBE52;display: inline-block;" v-if="item.regStatus == '在业' || item.regStatus == '存续' || item.regStatus == '在营' || item.regStatus == '开业'">{{item.regStatus}}</span>
              <span style="width: .80rem;height: .50rem;border: 1px solid red;line-height: .50rem;color: red;display: inline-block;" v-else>{{item.regStatus}}</span>
              </div>
            </li>
            <li class="list_info">
              <span>法定代表人</span>
              <span>{{item.legalPersonName}}</span>
            </li>
            <li class="list_info">
              <span>注册日期</span>
              <span>{{item.estiblishTime}}</span>
            </li>
            <li class="list_info">
              <span>注册资本</span>
              <span>{{item.regCapital}}</span>
            </li>
            <li  class="list_info" style="border-bottom: 1px solid #f2f2f2;">
              <span>电话</span>
              <span>{{item.phoneNumber}}</span>
            </li>
            <li  class="list_info_down">
              <img src="../../assets/sech/position.png" style="width: .3rem;height: .35rem;">
              <span style="margin-left: .4rem;text-align: left;line-height: .45rem;display: flex;align-items: center;width: 88%;">{{item.regLocation}}</span>
            </li>
          </ul>
        </div>
        <!-- 数据全部加载完毕显示 -->
        <span slot="doneTip">没有更多了</span>
      </yd-infinitescroll>
      <div v-if="isShow">
        <img src="../../assets/sech/no_tip.png" style="width: 4rem">
        <div style="margin-top: .3rem;">
          <span>暂无关注企业，</span><span style="color: red;" @click="lookBtn()">前去看看</span>
        </div>
      </div>

    </section>
</template>

<script>
    export default {
      name:'followList',
        data(){
          return{
            list:[],
            page:2,
            pageSize:10,
            isShow:false,
          }
        },
      methods:{
        lookBtn(){
          this.$router.push('/index');
        },
        detailInfo(item){
          this.$dialog.loading.open('正在加载');
          this.$ajax.post(window.g.apiUrl+'/detail/getComBasicF.do', JSON.stringify({
            localId: item.companyId,
          })).then((response) => {
            this.$dialog.loading.close();
            if (response.data.code == 200) {
              let obj = {};
              obj.id = item.companyId;
              obj.companyOrgType = response.data.result.companyOrgType == '' || response.data.result.companyOrgType == undefined ? '未公开' : response.data.result.companyOrgType;
              obj.regCapital = response.data.result.regCapital == '' || response.data.result.regCapital == undefined ? '未公开' : response.data.result.regCapital;
              obj.industry = response.data.result.industry == '' || response.data.result.industry == undefined ? '未公开' : response.data.result.industry;
              obj.name = response.data.result.name == undefined ? '' : response.data.result.name;
              obj.regStatus = response.data.result.regStatus == undefined ? '' : response.data.result.regStatus;
              obj.legalPersonName = response.data.result.legalPersonName == '' || response.data.result.legalPersonName == undefined ? '未公开' : response.data.result.legalPersonName;
              obj.estiblishTime = response.data.result.estiblishTime == undefined ? '' : response.data.result.estiblishTime.substr(0, 10);
              obj.regInstitute = response.data.result.regInstitute == '' || response.data.result.regInstitute == undefined ? '未公开' : response.data.result.regInstitute;
              obj.regLocation = response.data.result.regLocation == '' || response.data.result.regLocation == undefined ? '未公开' : response.data.result.regLocation;
              obj.businessScope = response.data.result.businessScope == '' || response.data.result.businessScope == undefined ? '未公开' : response.data.result.businessScope;
              obj.creditCode = response.data.result.creditCode == '' || response.data.result.creditCode == undefined ? '未公开' : response.data.result.creditCode;
              obj.orgNumber = response.data.result.orgNumber == '' || response.data.result.orgNumber == undefined ? '未公开' : response.data.result.orgNumber;
              obj.regNumber = response.data.result.regNumber == '' || response.data.result.regNumber == undefined ? '未公开' : response.data.result.regNumber;
              obj.flag = response.data.result.follow;
              obj.fromTime = response.data.result.fromTime == '' || response.data.result.fromTime == undefined ? '未公开' : new Date(parseInt(response.data.result.fromTime)).toLocaleDateString().split('/').join('-');
              obj.toTime = response.data.result.toTime == '' || response.data.result.toTime == undefined ? '无固定期限' : new Date(parseInt(response.data.result.toTime)).toLocaleDateString().split('/').join('-');
              obj.approvedTime = response.data.result.approvedTime == '' || response.data.result.approvedTime == undefined ? '未公开' : new Date(parseInt(response.data.result.approvedTime)).toLocaleDateString().split('/').join('-');
              sessionStorage.setItem('TO_OBJECT',JSON.stringify(obj));
              this.$router.push('/company_info');
            }else{
              this.$dialog.notify({
                mes:'查询失败，请稍后重试',
                timeout: 1500,
              });
            }
          }).catch(()=>{
          })

        },
        loadList() {
          const that = this;
          that.$ajax.post(window.g.apiUrl+'/account/getFollow.do', JSON.stringify({
            pageNum:that.page,
          })).then(function (response) {
            for(let i=0;i<response.data.result.items.length;i++){
              that.list.push(response.data.result.items[i])
            }
            response.data.result.items.forEach((val,oldval)=>{
              val.estiblishTime = val.estiblishTime.substr(0,10);
            })
            if (response.data.result.items.length < that.pageSize) {
              /* 所有数据加载完毕 */
              that.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
              return;
            }
            /* 单次请求数据完毕 */
            that.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.finishLoad');

            that.page++;
          });
        },
      },
      created(){
        const that = this;

        this.$ajax.post(window.g.apiUrl+'/user/isLog.do')
          .then((response)=>{
            if(response.data.code != 200){
              this.$dialog.notify({
                mes: '登录失效，正在跳转至登录页面',
                timeout: 1500,
                callback:()=>{
                  that.$router.push('/login');
                }
              });
            }else{
              that.$dialog.loading.open('正在加载');
              setTimeout(()=>{
                that.$ajax.post(window.g.apiUrl+'/account/getFollow.do',JSON.stringify({
                  pageNum:'1',
                })).then((response)=>{
                  that.$dialog.loading.close();
                  if(response.data.code == 200){
                    that.list = response.data.result.items;
                    if(response.data.result.total == 0){
                      that.isShow = true;
                    }
                    response.data.result.items.forEach((val,oldval)=>{
                      val.estiblishTime = val.estiblishTime.substr(0,10);
                    })
                  }else{
                    that.$dialog.notify({
                      mes: '信息加载失败，请稍后重试',
                      timeout: 1500,
                    })
                  }
                }).catch(()=>{
                })
              },150)
            }
          }).catch(()=>{
        })


      }
    }
</script>

<style scoped>
  .list_item{
    width: 96%;
    box-shadow: .1px .1px 3px 1px rgba(128,128,128,.2);
    margin-left: 2%;
    margin-top: .3rem;
    margin-bottom: .3rem;
    padding: .2rem .2rem .1rem .2rem;
  }
  .list_item:active{
    background: rgba(128,128,128,.04);
  }
  .list_info{
    display: flex;
    justify-content: space-between;
    padding: .16rem 0;
    align-items: flex-start;
  }
  .list_info_down{
    display: flex;
    align-items: flex-start;
    padding-top: .1rem;
  }
</style>
